//
//  KDMLoginView.m
//  KouDaiMaster
//
//  Created by 范智渊 on 2018/4/13.
//  Copyright © 2018年 zzgk. All rights reserved.
//

#import "KDMLoginView.h"

@implementation KDMLoginView {

    UIVisualEffectView *smallView;

    UIImageView* imgLeftHand;
    UIImageView* imgRightHand;

    UIImageView* imgLeftHandGone;
    UIImageView* imgRightHandGone;

}
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {

        [self creatVisulBg];

        [self creatSubViews];

    }

    return self;
}- (void)creatVisulBg {

    UIImageView *imageview = [[UIImageView alloc] initWithFrame:self.bounds];
    //    imageview.image = [UIImage imageNamed:@"bg.jpeg"];
    imageview.contentMode = UIViewContentModeScaleToFill;
    imageview.userInteractionEnabled = YES;
    [self addSubview:imageview];

    UIVisualEffectView *effectview = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
    effectview.frame = CGRectMake(0, 0, imageview.frame.size.width, imageview.frame.size.height);
    [imageview addSubview:effectview];

}

- (void)creatSubViews {

    smallView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
    smallView.frame = CGRectMake(20, 150, self.frame.size.width-40, self.frame.size.width-40);
    smallView.layer.cornerRadius = 5;
    smallView.layer.masksToBounds = YES;
    [self addSubview:smallView];



    UIButton *backBtn = [LSHControl createButtonWithFrame:(CGRectMake(20, 35, 25, 25)) ImageName:@"downBtn" Target:self Action:@selector(backBtnClick) Title:@""];
    backBtn.imageEdgeInsets = UIEdgeInsetsMake(7, 7, 7, 7);
    [self addSubview:backBtn];
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 15, smallView.frame.size.width-20, 20)];
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.font = [UIFont systemFontOfSize:20];
    [smallView.contentView addSubview:self.titleLabel];

    self.textField1 = [[UITextField alloc]initWithFrame:
                       CGRectMake(20, CGRectGetMaxY(self.titleLabel.frame)+15, smallView.frame.size.width-40, 40)];
    self.textField1.delegate = self;
    self.textField1.layer.cornerRadius = 5;
    self.textField1.layer.borderWidth = .5;
    self.textField1.clearButtonMode = UITextFieldViewModeWhileEditing;
    self.textField1.layer.borderColor = [UIColor grayColor].CGColor;
    self.textField1.placeholder = @"请输入手机号";

    self.textField1.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetHeight(self.textField1.frame), CGRectGetHeight(self.textField1.frame))];
    self.textField1.leftViewMode = UITextFieldViewModeAlways;
    UIImageView* imgUser = [[UIImageView alloc] initWithFrame:CGRectMake(9, 9, 22, 22)];
    imgUser.image = [UIImage imageNamed:@"iconfont-user"];
    [self.textField1.leftView addSubview:imgUser];
    [smallView.contentView addSubview:self.textField1];

    self.textField2 = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.textField1.frame), CGRectGetMaxY(self.textField1.frame)+10, CGRectGetWidth(self.textField1.frame), CGRectGetHeight(self.textField1.frame))];
    self.textField2.delegate = self;
    self.textField2.layer.cornerRadius = 5;
    self.textField2.layer.borderWidth = .5;
    self.textField2.clearButtonMode = UITextFieldViewModeWhileEditing;
    self.textField2.layer.borderColor = [UIColor grayColor].CGColor;
    self.textField2.placeholder = @"请输入密码";
    //  self.textField2.background = [UIImage imageNamed:@"underLine"];
    self.textField2.secureTextEntry = YES;
    self.textField2.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetHeight(self.textField2.frame), CGRectGetHeight(self.textField2.frame))];
    self.textField2.leftViewMode = UITextFieldViewModeAlways;
    UIImageView* imgPwd = [[UIImageView alloc] initWithFrame:CGRectMake(6, 6, 28, 28)];
    imgPwd.image = [UIImage imageNamed:@"iconfont-password"];
    [self.textField2.leftView addSubview:imgPwd];
    [smallView.contentView addSubview:self.textField2];


    //    登录按钮
    self.loginBtn = [[UIButton alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(self.textField2.frame)+20, smallView.frame.size.width-40, 50)];
    [self.loginBtn setTitle:@"登录" forState:UIControlStateNormal];
    self.loginBtn.layer.cornerRadius = 5;
    [self.loginBtn setBackgroundColor:FZYColor(199, 0, 11)];
    [self.loginBtn addTarget:self action:@selector(LoginAction:) forControlEvents:UIControlEventTouchUpInside];
    [smallView.contentView addSubview:self.loginBtn];
    self.loginBtn.layer.shadowRadius = 2;
    self.loginBtn.layer.shadowOpacity = 0.4;
    self.loginBtn.layer.shadowColor = FZYColor(199, 0, 11).CGColor;
    self.loginBtn.layer.shadowOffset = CGSizeMake(0, 2);

    //注册
    UIButton *EnrollBtn = [[UIButton alloc]initWithFrame:(CGRectMake(30, 380, 40, 20))];
    EnrollBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [EnrollBtn setTitleColor:FZYColor(36,59,107) forState:(UIControlStateNormal)];
    [EnrollBtn setTitle:@"注册" forState:(UIControlStateNormal)];
    [EnrollBtn addTarget:self action:@selector(enrollBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
    [self addSubview:EnrollBtn];

    //短信验证码登录
    UIButton *vcodeLoginBtn = [[UIButton alloc]init];
    vcodeLoginBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [vcodeLoginBtn setTitleColor:FZYColor(36,59,107) forState:(UIControlStateNormal)];
    [vcodeLoginBtn setTitle:@"短信验证码登录" forState:(UIControlStateNormal)];
    [vcodeLoginBtn addTarget:self action:@selector(vcodeLoginBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
    [self addSubview:vcodeLoginBtn];

    [vcodeLoginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(EnrollBtn.mas_top);
        make.centerX.equalTo(self.mas_centerX);
        make.width.equalTo(@140);
        make.height.equalTo(@20);

    }];

    //忘记密码
    UIButton *forgetPwdBtn = [[UIButton alloc]initWithFrame:(CGRectMake(self.bounds.size.width-120, 380,90, 20))];
    forgetPwdBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [forgetPwdBtn setTitleColor:FZYColor(36,59,107) forState:(UIControlStateNormal)];
    [forgetPwdBtn setTitle:@"忘记密码" forState:(UIControlStateNormal)];
    [forgetPwdBtn addTarget:self action:@selector(forgetPwdBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
    [self addSubview:forgetPwdBtn];


    UILabel *thirdLab = [[UILabel alloc]initWithFrame:(CGRectMake((APPW-90)/2, forgetPwdBtn.mj_y+forgetPwdBtn.mj_h+30, 90, 20))];
    thirdLab.text = @"第三方登录";
    thirdLab.font = [UIFont systemFontOfSize:14];
    thirdLab.textAlignment = NSTextAlignmentCenter;
    thirdLab.textColor = FZYColor(175,182,192);
    [self addSubview:thirdLab];
    UILabel *underLine = [[UILabel alloc]initWithFrame:(CGRectMake((APPW-90-20-90*2)/2, thirdLab.mj_y+10, 90, .5))];
    underLine.backgroundColor = [UIColor grayColor];
    [self addSubview:underLine];
    UILabel *underLine1 =  [[UILabel alloc]initWithFrame:(CGRectMake((APPW/2+90/2+10), thirdLab.mj_y+10, 90,  .5))];
    underLine1.backgroundColor = [UIColor grayColor];
    [self addSubview:underLine1];


    self.qqBtn = [[UIButton alloc]initWithFrame:(CGRectMake(APPW/2-20-40, thirdLab.mj_h+thirdLab.mj_y+12, 50, 50))];
    [self.qqBtn setBackgroundImage:[UIImage imageNamed:@"qq"] forState:(UIControlStateNormal)];
    self.qqBtn.imageEdgeInsets = UIEdgeInsetsMake(-20, -10, -20, -10);

    self.qqBtn.imageView.contentMode = UIViewContentModeScaleAspectFill;
    [self.qqBtn addTarget:self action:@selector(getAuthWithUserInfoFromQQ) forControlEvents:(UIControlEventTouchUpInside)];
    [self addSubview:_qqBtn];

    self.wxBtn = [[UIButton alloc]initWithFrame:(CGRectMake(APPW/2-20+40, thirdLab.mj_h+thirdLab.mj_y+12, 50, 50))];
    [self.wxBtn setBackgroundImage:[UIImage imageNamed:@"wx"] forState:(UIControlStateNormal)];
    [self.wxBtn addTarget:self action:@selector(getAuthWithUserInfoFromWX)  forControlEvents:(UIControlEventTouchUpInside)];

    [self addSubview:_wxBtn];

    smallView.frame = CGRectMake(20, 150, self.frame.size.width-40, CGRectGetMaxY(self.loginBtn.frame)+15);
}

@end
